<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/style.css">
    <title>销售单据</title>
    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/config.js"></script>
    <script src="js/message.js"></script>

</head>
<body >
<div class="nei_header" >

    <h3>销售单据</h3>
     <div class="rentu">
         <img src="images/gongnengguanli.png" alt="" onclick="location.href='tab.html'">
     </div>
</div>


<div class="danju_con">

    <div class="danju_left">

        <div class="dan_query" style="border: none;margin-top: 9px">
            时间：<input id="time" type="date" onchange="query()">
        </div>
        <div class="dan_query" style="border: none;margin-top: 9px">
            状态：
            <select style="width:160px;height: 25px;" id="status" onchange="query()">
                <option value="">请选择</option>
                <option value="0">待支付</option>
                <option value="1">支付成功</option>
                <option value="4">退款</option>
            </select>
        </div>
        <div class="dan_title" style="border: none;margin-top: 9px">
            流水号   <span>总额</span>
        </div>

        <div class="danju_lis">
            <ul id="order">
            </ul>
            <div class="page" style="border: none;margin-top: 10px">
                <span onclick="initTable(false)">上页</span>
                <span id="pageText">1/1</span>
                <span onclick="initTable(true)">下页</span>
            </div>
            
        </div>
    </div>


    <div class="danju_max">
        <div class="cont_box editpro_box">
            <div class="da_title box_sd">
                <ul>
                    <li>
                        <span>条形码</span>
                        <span>商品名称</span>
                        <span>数量</span>
                        <span>交易单价(元)</span>
                        <span>金额(元)</span>
                    </li>
                </ul>

            </div>
            <div class="box_sd content-about">
                <ul id="detailBody">
                </ul>
            </div>

        </div>


    </div>

</div>


</body>
<script type="text/javascript">
    var page = 0;
    var total = 0;

    //希望每次打开都要默认为今天日期+00:00
    // 默认时间
    var myDate = new Date(), Y = myDate.getFullYear(), M = myDate.getMonth() + 1, D = myDate.getDate();
    //处理月是一位的情况
    if((M + '').length == 1){
        M = '0' + (M + '');
    }
    //处理日是一位的情况
    if((D + '').length == 1){
        D = '0' + (D + '')
    }
    var curDay = Y + '-' + M + '-' + D;
    $("#time").val(curDay)


    function initTable(b) {
        if (b) {
            if (total == 0 && page > 0) {
                $.message({
                    message: "无数据",    //提示信息
                    duration: 3000,
                    type: 'info',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            } else if (total != 0 && total == page) {
                $.message({
                    message: "已是末页",    //提示信息
                    duration: 3000,
                    type: 'warning',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            }
            page++;
        } else {
            if (page == 1) {
                $.message({
                    message: "已是首页",    //提示信息
                    duration: 3000,
                    type: 'warning',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            }
            page--;
        }
        let time = $("#time").val();
        let sTime = null;
        let eTime = null;
        if(time != undefined && time != null && time != ""){
            sTime = time + "T00:00:00";
            eTime = time + "T23:59:59";
        }
        cashierPost("order/list.do", {sTime: sTime,eTime: eTime, status: $("#status").val(), pageNo: page, pageSize: 10}, someFunction);
    }


    function query() {
        page = 0;
        total = 0;
        let time = $("#time").val();
        let sTime = null;
        let eTime = null;
        if(time != undefined && time != null && time != ""){
            sTime = time + "T00:00:00";
            eTime = time + "T23:59:59";
        }
        cashierPost("order/list.do", {sTime: sTime,eTime: eTime, status: $("#status").val(), pageNo: page, pageSize: 10}, someFunction);
    }
    function someFunction(result) {
        let tableHtml = "";
        if (result.list == null || result.list.length <= 0) {
            $.message({
                message: "无数据",    //提示信息
                duration: 3000,
                type: 'success',           //显示类型，包括4种：success.error,info,warning 默认info
                showClose: false       //显示关闭按钮（默认：否）
            });
            $("#order").html(tableHtml);
            $("#detailBody").html("");
            page = 0;
            total = 0;
            return;
        } else {
            for (let m of result.list) {
                tableHtml +=
                    "<li onclick=\"onDetail('"+ m.orderEdsc +"')\">"
                        + m.orderId +"<span>￥"+ m.actualPay +"</span> " +
                    "</li>";
            }
        }
        $("#order").html(tableHtml);
        total = result.pages;
        $("#pageText").text(page + "/" + total);
        $("#detailBody").html("");
    }

    function onDetail(orderEdsc) {
        cashierPost("detail/list.do", {orderId: orderEdsc}, detailFunction);
    }

    function detailFunction(result) {
        let tableHtml = "";
        if (result == null || result.length <= 0) {
            $.message({
                message: "明细无数据",    //提示信息
                duration: 3000,
                type: 'success',           //显示类型，包括4种：success.error,info,warning 默认info
                showClose: false       //显示关闭按钮（默认：否）
            });
            return;
        } else {
            for (let m of result) {
                tableHtml +=
                    `<li>
                        <span>${m.goodsCode}</span>
                        <span>${m.goodsName}</span>
                        <span>${m.num}</span>
                        <span>${m.currentPrice}</span>
                        <span>${m.subtotal}</span>
                    </li>`;
            }
        }
        $("#detailBody").html(tableHtml);
    }

    $(function () {
        query();
    });
</script>

</html>